<?php
/**
 * @Copyright Copyright (C) 2010-2012
 * @license GNU/GPL http://www.gnu.org/copyleft/gpl.html
 + Created by:          Webit Solution
 * Company:		Webit Solution
 + Contact:		www.webits.asia, developer@webits.asia
 * Created on:	Mar 21, 2012
 ^
 + Project: 		WRecruit
 * File Name:	views/employer/view.html.php
 ^
 * Description: HTML view class for employer
 ^
 * History:		NONE
 ^
 */

defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.view');
jimport('joomla.html.pagination');
require_once 'html/utilities.php';
class WRecruitViewEmployer extends JView
{

	function display($tpl = null)
	{
		global $mainframe, $sorton, $sortorder, $option;

		$user	=& JFactory::getUser();
		$uid    =$user->id;
		$viewtype = 'html';
		$type = 'offl';
		$option = 'com_wrecruit';
		$userrole = Array();


		$mainframe = &JFactory::getApplication();

		$version = new JVersion;
		$joomla = $version->getShortVersion();
		$jversion = substr($joomla,0,3);

		$itemid =  JRequest::getVar('Itemid');
		$document	   =& JFactory::getDocument();

		$layout =  JRequest::getVar('layout');
		//14052012
		if (JRequest::getVar('sorted_field')!=""){
			$sorted_field = JRequest::getVar('sorted_field');
		}else $sorted_field = "name";
		//



		$model = &$this->getModel();

		// get configurations
		//$config = Array();
		$session = JFactory::getSession();
		$config = $session->get('jsjobconfig_dft');		
		$curuser = $session->get('jsjobcur_usr');
		if($curuser != $uid) unset($config);
		$session->set('jsjobcur_usr', $uid);
//		if(isset($config))
		//echo $config['testing_mode'];
//		if($config['testing_mode'] == 1)	unset($config);
		if(!isset($config)){
			$results =  $model->getConfig('');
			if ($results){ //not empty
				foreach ($results as $result){
					$config[$result->configname] = $result->configvalue;
				}
				$result =  $model->getTypeStatus();
				$type .= $result[0];
				$value = $result[1];
				if ($config[$type] != 1) $config[$type] = $value;
				$session->set('jsjobconfig_dft', $config);
				//$_SESSION['jsjobconfig_dft'] = $config;
			}

		}
		$config['offline'] = 0;
		$needlogin = true;
		
		switch($layout){
			case 'controlpanel': if ($config['visitorview_emp_conrolpanel'] == 1) $needlogin = true; break;
			case 'packages': if ($config['visitorview_emp_packages'] == 1) $needlogin = true; break;
			case 'package_details': if ($config['visitorview_emp_viewpackage'] == 1) $needlogin = true; break;
			case 'resumesearch': if ($config['visitorview_emp_resumesearch'] == 1) $needlogin = true; break;
			case 'resumesearchresult': if ($config['visitorview_emp_resumesearchresult'] == 1) $needlogin = true; break;
			case 'view_company': if ($config['visitorview_emp_viewcompany'] == 1) $needlogin = true; break;
			case 'view_job': if ($config['visitorview_emp_viewjob'] == 1) $needlogin = false; break;
			default : $needlogin = true; break;
		}
		
		if ($user->guest) { // redirect user if not login
			if($needlogin){				
				$_SESSION['wrecruit_option'] = 'com_wrecruit';
				$_SESSION['wrecruit_view'] = 'employer';
				$_SESSION['wrecruit_red_layout'] = $layout;
				$msg = JText::_('JS_LOGIN_DESCRIPTION');
				$msg = "";
				$redirectUrl = 'index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=successfullogin';
				$redirectUrl = '&amp;return='.base64_encode($redirectUrl);
				//$finalUrl = 'index.php?option=com_user&view=login'. $redirectUrl;
				if($config['login_redirect']){
					$finalUrl = $config['login_redirect']. $redirectUrl;

				}else{
					if($jversion == '1.5'){
						$finalUrl = 'index.php?option=com_user&view=login'. $redirectUrl;
					}else{
						$finalUrl = 'index.php?option=com_users&view=login'. $redirectUrl;
					}

				}
				$mainframe->redirect($finalUrl,$msg);
			}
		}

		$limit		= $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
		//$limitstart	= $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );
		$limitstart	= JREQUEST::getVar('limitstart', 0, 'int' );

		if (isset($_SESSION['wrecruit_layout'])){
			if ($layout != $_SESSION['wrecruit_layout']) {
				$_SESSION['wrecruit_layout'] = $layout;
				$limitstart = 0;
			}
		}else $_SESSION['wrecruit_layout'] = $layout;

		$params = & $mainframe->getPageParameters('com_wrecruit');

		// get user role
		if (isset($_SESSION['jsuserrole'])) $userrole = $_SESSION['jsuserrole']; else $userrole=null;
		//$config = Array();
		if($curuser != $uid) unset($userrole);
		if (sizeof($userrole) == 0){
			$userrole =  $model->getUserRole($uid);
			if (isset($userrole)){ //not empty
				$_SESSION['jsuserrole'] = $userrole;
			}else{
				if ($layout != 'view_job') {
					if (! $user->guest){//echo '<br> new in wrecruit';
						$mainframe->redirect('index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=new_inwrecruit&Itemid='.$itemid);
					}
				}
			}
		}
			
		$themevalue = $config['theme'];
		if ($themevalue != 'templatetheme.css'){
			$theme['title'] = 'jppagetitle';
			$theme['heading'] = 'pageheadline';
			$theme['sectionheading'] = 'sectionheadline';
			$theme['sortlinks'] = 'sortlnks';
			$theme['odd'] = 'odd';
			$theme['even'] = 'even';
		}else{
			$theme['title'] = 'componentheading';
			$theme['heading'] = 'contentheading';
			$theme['sectionheading'] = 'sectiontableheader';
			$theme['sortlinks'] = 'sectiontableheader';
			$theme['odd'] = 'sectiontableentry1';
			$theme['even'] = 'sectiontableentry2';
		}




		//Start company menu.
//		echo $userrole->rolefor;exit;
		if(isset($userrole->rolefor)) {
			
			if ($userrole->rolefor == 1) { // employer
				// WR Company				
				$result =  $model->getMyCompanies($uid,$limit,$limitstart);
				$wr_company = $result[0][0];				
				if($config['tmenu_emcontrolpanel'] == 1){$link = 'index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=controlpanel&Itemid='.$itemid;
				$employerlinks [] = array($link, JText::_('JS_CONTROL_PANEL'),1);
				}if($config['tmenu_emnewjob'] == 1){
					$link = 'index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=formjob&Itemid='.$itemid;
					$employerlinks [] = array($link, JText::_('JS_NEW_JOB'),0);
				}if($config['tmenu_emmyjobs'] == 1){
					$link = 'index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=myjobs&Itemid='.$itemid;
					$employerlinks [] = array($link, JText::_('JS_MY_JOBS'),0);
				}if($config['tmenu_emmycompanies'] == 1){
					//$link = 'index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=mycompanies&Itemid='.$itemid;
					//view profile
					$link = 'index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=view_company&vm=1&md='.$wr_company->id;
					$employerlinks [] = array($link, JText::_('My Profile'),0);
					//edit profile
					$link = 'index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=formcompany&md='.$wr_company->id;
					$employerlinks [] = array($link, JText::_('Edit Profile'),0);
				}if($config['tmenu_emappliedresume'] == 1){
					$link = 'index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=alljobsappliedapplications&Itemid='.$itemid;
					$employerlinks [] = array($link, JText::_('JS_APPLIED_RESUME'),-1);
				}
			}else{

				//		if ($cur_user_allow[1] == 1) { // Emp Allow
				$link = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=controlpanel&Itemid='.$itemid;
				$jobseekerlinks [] = array($link, JText::_('JS_CONTROL_PANEL'),1);


				$link = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=jobcat&Itemid='.$itemid;
				$jobseekerlinks [] = array($link, JText::_('JS_JOB_CATEGORIES'),0);

				$link = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=jobsearch&Itemid='.$itemid;
				$jobseekerlinks [] = array($link, JText::_('JS_SEARCH_JOB'),0);

				$link = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=listnewestjobs&Itemid='.$itemid;
				$jobseekerlinks [] = array($link, JText::_('JS_NEWEST_JOBS'),0);
					
				$link = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=myresumes&Itemid='.$itemid;
				$jobseekerlinks [] = array($link, JText::_('JS_MY_RESUMES'),-1);

			}
		}else{ // user not logined
			$link = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=controlpanel&Itemid='.$itemid;
			$jobseekerlinks [] = array($link, JText::_('JS_CONTROL_PANEL'),1);

			$link = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=jobcat&Itemid='.$itemid;
			$jobseekerlinks [] = array($link, JText::_('JS_JOB_CATEGORIES'),0);

			$link = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=jobsearch&Itemid='.$itemid;
			$jobseekerlinks [] = array($link, JText::_('JS_SEARCH_JOB'),0);

			$link = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=listnewestjobs&Itemid='.$itemid;
			$jobseekerlinks [] = array($link, JText::_('JS_NEWEST_JOBS'),0);

			$link = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=myresumes&Itemid='.$itemid;
			$jobseekerlinks [] = array($link, JText::_('JS_MY_RESUMES'),-1);
		}
//		print_r($employerlinks);exit;
		//End Link Company Menu

		$page_title = $params->get('page_title');

		if($layout== 'myjobs'){ 							// my jobs
			$page_title .=  ' - ' . JText::_('JS_MY_JOBS');
			if (isset($_GET['sortby']))
			$sort = $_GET['sortby'];

			$sort =  JRequest::getVar('sortby','');
			if (isset($sort)){
				if ($sort == '')
				{$sort='createddesc';}
			}else
			{$sort='createddesc';}
			$sortby = $this->getJobListOrdering($sort);
			$result =  $model->getMyJobs($uid,$sortby,$limit,$limitstart);
			$sortlinks = $this->getJobListSorting($sort);
			$sortlinks['sorton'] = $sorton;
			$sortlinks['sortorder'] = $sortorder;
			$this->assignRef('jobs', $result[0]);
			$this->assignRef('listjobconfig',$result[2]);
			if ( $result[1] <= $limitstart ) $limitstart = 0;
			$pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
			$this->assignRef('sortlinks', $sortlinks);
		}elseif($layout== 'my_stats'){ 							// my stats
			$page_title .=  ' - ' . JText::_('JS_MY_STATS');
			$result =  $model->getMyStats_Employer($uid);
			$this->assignRef('companiesallow', $result[0]);
			$this->assignRef('totalcompanies', $result[1]);
			$this->assignRef('jobsallow', $result[2]);
			$this->assignRef('totaljobs', $result[3]);
			$this->assignRef('featuredcompainesallow', $result[4]);
			$this->assignRef('totalfeaturedcompanies', $result[5]);
			$this->assignRef('goldcompaniesallow', $result[6]);
			$this->assignRef('totalgoldcompanies', $result[7]);
			$this->assignRef('goldjobsallow', $result[8]);
			$this->assignRef('totalgoldjobs', $result[9]);
			$this->assignRef('featuredjobsallow', $result[10]);
			$this->assignRef('totalfeaturedjobs', $result[11]);
		}elseif($layout== 'controlpanel'){
			$emcontrolpanel = $model->getConfigByFor('emcontrolpanel');
			$this->assignRef('emcontrolpanel', $emcontrolpanel);
		}
		/*---12052012--*/
		elseif ($layout== 'candidatepool'){
			$page_title .=  ' - ' . JText::_('JS_CANDIDATE_POOL');
			$page = JRequest::getVar("page");
			$number_show = 5;
			if($page > 1){
				$p	=	$page;
			}
			else{
				$p	=	1;
			}
			$start	=	($p-1)*$number_show;
			$result = $model->getCandidatePool($uid,$sorted_field, $start, $number_show);
			$this->assignRef('candidatepools',$result);
		}

		elseif ($layout=='test'){
			$page_title =  ' - Employer post job';
			$info = $model->getInfoforJob($page_title);
			$this->assignRef('info',$info);
			$this->assignRef('experience',$model->getExperiences("Require experience"));
		}
		elseif ($layout=='postjob') {
			$result =  $model->getMyCompanies($uid,$limit,$limitstart);
			$wr_company = $result[0][0];
			$page_title .=  ' - ' . JText::_('JS_JOB_INFO');
			if (isset($_GET['bd']))
			$jobid = $_GET['bd'];
			if (!isset($jobid)) $jobid='';
			$result =  $model->getInfoJobform($jobid, $uid);
			$pool = $model->inviteCandidatePool($uid);
			$this->assignRef('candidatepools',$pool);
			
			//ch_debug($result[1]);
			$this->assignRef('wr_company',$wr_company);
			$this->assignRef('job', $result[0]);
			$this->assignRef('lists', $result[1]);
			$this->assignRef('userfields', $result[2]);
			$this->assignRef('fieldsordering', $result[3]);
			$this->assignRef('canaddnewjob', $result[4]);
			$this->assignRef('packagedetail', $result[5]);
			
			JHTML::_('behavior.formvalidation');
		}
		elseif ($layout== 'myjob'){
			$page_title .=  ' - ' . JText::_('JS_MY_JOBS');
			$sort = JRequest::getVar("sort");
			$page = JRequest::getVar("page",1);
			$number_show = 5;
			if($page > 1){
				$p	=	$page;
			}
			else{
				$p	=	1;
			}
			$start	=	($p-1)*$number_show;
			$result = $model->getMyjob($uid, $sort, $start, $number_show);
			$this->assignRef('myjobs',$result);
		}
		
		elseif ($layout== 'cvdetails'){
			$page_title .=  ' - Review Candidate\'cv details';
			$canduid = JRequest::getVar('cuid','0');
			$result = $model->requestCVDetails($canduid);
			$this->assignRef('cvdetails',$result);	
		}
		
		elseif ($layout== 'messagelist'){
			$page_title .=  ' - Message Listing';
			$box		 = JRequest::getVar('box','candidate_sent');
			$sort = JRequest::getVar('sort','DESC'); 
			$page = JRequest::getVar("page",1);
			$number_show = 5;
			if($page > 1){
				$p	=	$page;
			}
			else{
				$p	=	1;
			}
			$start	=	($p-1)*$number_show;
			$result = $model->messageList($box,$sort, $start, $number_show);
			$this->assignRef('messages',$result);	
		}
		elseif ($layout== 'messagedetail'){
			$page_title .=  ' - Message Details';
			$mid	= JRequest::getVar('mid');
			$result = $model->messageDetail($mid);
			$this->assignRef('message',$result);
		}
		elseif ($layout=='account-profile') {
			$page_title .=  ' - Employer account and profile';
			$result = $model->employerProfile($uid);
			$this->assignRef('information',$result);
		}
		

		elseif($layout == "add2pool"){
			$config	= JFactory::getConfig();
			$user = JFactory::getUser();
			$resume		 = JRequest::getVar('resume');
			$rows = $model->add2poolList($resume, $user->get('id'));
			return "OK";
		}
		elseif($layout == "sentdetail"){
			// get all admin users
			$config	= JFactory::getConfig();
			$user = JFactory::getUser();			
//			$db		= $this->getDbo();
			$data['fromname'] = $config->get('fromname');
			$data['mailfrom'] = $config->get('mailfrom');
//			echo "fromname = ".$user->get('name')."<br />";
//			echo "mailfrom = ".$user->get('email')."<br />";
			$rows =  $model->getUserEmail($uid,$limit,$limitstart);
			/*$query = 'SELECT name, email, sendEmail' .
						' FROM #__users' .
						' WHERE sendEmail=1';

			$db->setQuery( $query );
			$rows = $db->loadObjectList();*/
			
			$emailSubject	= JText::sprintf(
				'COM_JS_JOB_REQURST_FOR_DEDETAIL_CV'
			);

			$emailBody = JText::sprintf(
				'COM_JS_JOB_REQURST_FOR_DEDETAIL_CV_BODY'				
			);
//			echo "emailSubject = ".$emailSubject."<br />";
//			echo "emailBody = ".$emailBody."<br />";
			foreach( $rows as $row )
			{
//				$return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $row->email, $emailSubject, $emailBody);
				$return = JUtility::sendMail($user->get('email'), $user->get('name'), $row->email, $emailSubject, $emailBody);
				// Check for an error.
				if ($return !== true) {
//					$this->setError(JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED'));
					return false;
				}
			}
			return "OK";
		}
		/*---end--*/
		elseif($layout== 'mycompanies'){ 							// my companies
			$page_title .=  ' - ' . JText::_('JS_MY_COMPANIES');
			$result =  $model->getMyCompanies($uid,$limit,$limitstart);
			$companies = $result[0];
			$this->assignRef('companies', $companies);
			if ( $result[1] <= $limitstart ) $limitstart = 0;
			$pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
		}elseif($layout== 'mydepartments'){ 							// my departments
			$page_title .=  ' - ' . JText::_('JS_MY_DEPARTMENTS');
			$result =  $model->getMyDepartments($uid,$limit,$limitstart);
			$departments = $result[0];
			$totalresults = $result[1];
			$this->assignRef('departments', $departments);
			if ( $result[1] <= $limitstart ) $limitstart = 0;
			$pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
		}elseif($layout== 'alljobsappliedapplications'){				 // all jobs applied application
			$page_title .=  ' - ' . JText::_('JS_APPLIED_RESUME');
			if (isset($_GET['sortby']))
			$sort = $_GET['sortby'];

			$sort =  JRequest::getVar('sortby','');
			if (isset($sort)){
				if ($sort == '')
				{$sort='createddesc';}
			}else
			{$sort='createddesc';}
			$sortby = $this->getJobListOrdering($sort);
			$result =  $model->getJobsAppliedResume($uid,$sortby,$limit,$limitstart);
			$sortlinks = $this->getJobListSorting($sort);
			if ( $result[1] <= $limitstart ) $limitstart = 0;
			$pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
			$sortlinks['sorton'] = $sorton;
			$sortlinks['sortorder'] = $sortorder;
			$this->assignRef('jobs', $result[0]);
			$this->assignRef('sortlinks', $sortlinks);
		}elseif($layout== 'job_shortlistcandidates'){									 // job applied applications
			$page_title .=  ' - ' . JText::_('JS_SHORT_LIST_CANDIDATES');



			$sort =  JRequest::getVar('sortby','');
			if (isset($sort)){
				if ($sort == '')
				{$sort='apply_datedesc';}
			}else
			{$sort='apply_datedesc';}
			$sortby = $this->getEmpListOrdering($sort);
			//$jobid = $_GET['jobid'];

			//$result =  $model->getJobAppliedResume($uid,$jobid,$sortby,$limit,$limitstart);





			$jobid =  JRequest::getVar('bd','');

			$result =  $model->getShortListCandidate($jobid,$sortby ,$limit,$limitstart);
			$sortlinks = $this->getEmpListSorting($sort);
			$sortlinks['sorton'] = $sorton;
			$sortlinks['sortorder'] = $sortorder;
			$this->assignRef('candidatelist', $result[0]);
			if ( $result[1] <= $limitstart ) $limitstart = 0;
			$pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
			$this->assignRef('jobid', $jobid);
			$this->assignRef('sortlinks', $sortlinks);

		}elseif($layout== 'job_appliedapplications'){									 // job applied applications
			$page_title .=  ' - ' . JText::_('JS_JOB_APPLIED_APPLICATIONS');
			if (isset($_GET['sortby']))
			$sort = $_GET['sortby'];

			$sort =  JRequest::getVar('sortby','');
			if (isset($sort)){
				if ($sort == '')
				{$sort='apply_datedesc';}
			}else
			{$sort='apply_datedesc';}
			$sortby = $this->getEmpListOrdering($sort);
			//$jobid = $_GET['jobid'];
			$jobid =  JRequest::getVar('bd','');

			$result =  $model->getJobAppliedResume($uid,$jobid,$sortby,$limit,$limitstart);
			$application = $result[0];
			$totalresults = $result[1];
			$sortlinks = $this->getEmpListSorting($sort);
			$sortlinks['sorton'] = $sorton;
			$sortlinks['sortorder'] = $sortorder;
			$this->assignRef('resume', $result[0]);
			$this->assignRef('jobsearches', $result[0]);
			if ( $result[1] <= $limitstart ) $limitstart = 0;
			$pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
			$this->assignRef('sortlinks', $sortlinks);
			$this->assignRef('jobid', $jobid);
		}elseif($layout== 'view_department'){ 															// view company
			if (isset($_GET['pd']))
			$departmentid = $_GET['pd'];
			if (!isset($departmentid)) $departmentid='';

			$departmentid =  JRequest::getVar('pd','');
			$department =  $model->getDepartmentbyId($departmentid);
			$this->assignRef('department', $department);
			$this->assignRef('vp', JRequest::getVar('vp',''));
			if (isset($department)){
				$page_title .=  ' - ' . $department->name;
				//if ($mainframe->getCfg('MetaTitle') == '1') $mainframe->addMetaTag('title', $department->name);
			}

		}elseif($layout== 'view_company'){ 															// view company
			if (isset($_GET['md']))
			$companyid = $_GET['md'];
			if (!isset($companyid)) $companyid='';

			$companyid =  JRequest::getVar('md','');
			$result =  $model->getCompanybyId($companyid);
			$company = $result[0];
			$this->assignRef('company', $company);
			$this->assignRef('userfields', $result[2]);
			$this->assignRef('fieldsordering', $result[3]);
			$this->assignRef('vm', JRequest::getVar('vm',''));
			$this->assignRef('jobcat', JRequest::getVar('jobcat',''));
			if (isset($company)){
				$page_title .=  ' - ' . $company->name;
				//if ($mainframe->getCfg('MetaTitle') == '1') $mainframe->addMetaTag('title', $company->name);
			}

		}elseif($layout== 'view_job'){ 															// view job
			if (isset($_GET['oi']))
			$jobid = $_GET['oi'];
			if (!isset($jobid)) $jobid='';
			$jobid =  JRequest::getVar('oi','');
			$result =  $model->getJobbyId($jobid);
			$job = $result[0];
			$companyid =  $job->companyid;
			$company_result =  $model->getCompanybyId($companyid);
			$company = $company_result[0];
			$this->assignRef('job', $result[0]);
			$this->assignRef('company', $company);
			$this->assignRef('userfields', $result[2]);
			$this->assignRef('fieldsordering', $result[3]);
			$this->assignRef('listjobconfig', $result[4]);
			$this->assignRef('vj', JRequest::getVar('vj',''));
			//$this->assignRef('canviewvideo', $result[5]);
			//$this->assignRef('canviewmap', $result[4]);

			//$this->assignRef('companyid', JRequest::getVar('cd',''));

			if (isset($job)){
				$page_title .=  ' - ' . $job->title;
				$document->setDescription( $job->metadescription );
				$document->setMetadata('keywords', $job->metakeywords);
				//if ($mainframe->getCfg('MetaTitle') == '1') $mainframe->addMetaTag('title', $job->title);
			}

		}elseif($layout== 'formdepartment'){									//form department
			$page_title .=  ' - ' . JText::_('JS_DEPARTMENT_INFO');
			$departmentid =  JRequest::getVar('pd','');
			//$depid=2;

			$result =$model->getDepartmentByIdForForm($departmentid,$uid);

			$this->assignRef('department', $result[0]);
			$this->assignRef('lists', $result[1]);
			JHTML::_('behavior.formvalidation');
		}elseif($layout== 'formjob'){	// WR Form job											// form job
			$result =  $model->getMyCompanies($uid,$limit,$limitstart);
			$wr_company = $result[0][0];
			$page_title .=  ' - ' . JText::_('JS_JOB_INFO');
			if (isset($_GET['bd']))
			$jobid = $_GET['bd'];
			if (!isset($jobid)) $jobid='';

			$result =  $model->getJobforForm($jobid, $uid);
			//ch_debug($result[1]);
			$this->assignRef('wr_company',$wr_company);
			$this->assignRef('job', $result[0]);
			$this->assignRef('lists', $result[1]);
			$this->assignRef('userfields', $result[2]);
			$this->assignRef('fieldsordering', $result[3]);
			$this->assignRef('canaddnewjob', $result[4]);
			$this->assignRef('packagedetail', $result[5]);
			JHTML::_('behavior.formvalidation');
		}elseif($layout== 'formcompany'){											// form company
			$page_title .=  ' - ' . JText::_('JS_COMPANY_INFO');
			if (isset($_GET['md']))
			$companyid = $_GET['md'];
			$companyid =  JRequest::getVar('md','');
			if (!isset($companyid)) $companyid='';

			$result =  $model->getCompanybyIdforForm($companyid, $uid);
			$this->assignRef('company', $result[0]);
			$this->assignRef('lists', $result[1]);
			$this->assignRef('userfields', $result[2]);
			$this->assignRef('fieldsordering', $result[3]);
			$this->assignRef('canaddnewcompany', $result[4]);
			$this->assignRef('packagedetail', $result[5]);
			JHTML::_('behavior.formvalidation');
		}elseif($layout== 'formfolder'){											// form company
			$page_title .=  ' - ' . JText::_('JS_FOLDERS_INFO');
			$folderid =  JRequest::getVar('fd','');
			$result =  $model->getFolderbyIdforForm($folderid, $uid);
			$this->assignRef('folders', $result[0]);
			$this->assignRef('canaddnewfolder', $result[1]);
			$this->assignRef('packagedetail', $result[2]);
			JHTML::_('behavior.formvalidation');
		}elseif($layout== 'resumesearch'){											// resume search
			$page_title .=  ' - ' . JText::_('JS_RESUME_SEARCH');
			$result =  $model->getResumeSearchOptions($uid);
			$this->assignRef('searchoptions', $result[0]);
			$this->assignRef('searchresumeconfig', $result[1]);
			$this->assignRef('canview', $result[2]);
			
		}elseif( $layout== 'basicinfo'){
			$resumeid = $_REQUEST['resumeid'];			
			$result =  $model->getResumeBasic($resumeid);
			$this->assignRef('basicinfo', $result);
		}elseif($layout== 'resume_searchresults'){ 															// resume search results
			$page_title .=  ' - ' . JText::_('JS_RESUME_SEARCH_RESULT');
			if (isset($_GET['sortby']))
			$sort = $_GET['sortby'];

			$sort =  JRequest::getVar('sortby','');
			if (isset($sort)){
				if ($sort == '') {$sort='create_datedesc';}
			}else{$sort='create_datedesc';}
			
			$sortby = $this->getResumeListOrdering($sort);				
			if ($limit != '') {	$_SESSION['limit']=$limit;
			}else if ($limit == '') {$limit=$_SESSION['limit'];	}
			if (isset($_POST['isresumesearch'])){
				if ($_POST['isresumesearch'] == '1'){
					if ($_POST['title'] == 'CV Title...'){ $_POST['title'] = ""; }
					if ($_POST['name'] == 'Candidate Name...'){ $_POST['name'] = ""; }					
					$_SESSION['resumesearch_title'] = $_POST['title'];
					$_SESSION['resumesearch_name'] = $_POST['name'];
					$_SESSION['resumesearch_nationality'] = $_POST['nationality'];
					$_SESSION['resumesearch_gender'] = $_POST['gender'];
					if (isset($_SESSION['resumesearch_iamavailable'])) $_SESSION['resumesearch_iamavailable'] = $_POST['iamavailable'];
					$_SESSION['resumesearch_jobcategory'] = $_POST['jobcategory'];
					$_SESSION['resumesearch_jobtype'] = $_POST['jobtype'];
					if(isset($_POST['jobsalaryrange'])) $_SESSION['resumesearch_jobsalaryrange'] = $_POST['jobsalaryrange'];
					$_SESSION['resumesearch_heighestfinisheducation'] = $_POST['heighestfinisheducation'];
					$_SESSION['resumesearch_experience'] = $_POST['experience'];
					$_SESSION['resumesearch_currency'] = $_POST['currency'];
				}
			}
			$jobstatus='';
			$title = $_SESSION['resumesearch_title'];
			$name = $_SESSION['resumesearch_name'];
			$nationality = $_SESSION['resumesearch_nationality'];
			$gender = $_SESSION['resumesearch_gender'];
			$iamavailable = '';//$_SESSION['resumesearch_iamavailable'];
			$jobcategory = $_SESSION['resumesearch_jobcategory'];
			$jobtype = $_SESSION['resumesearch_jobtype'];
			$jobsalaryrange = $_SESSION['resumesearch_jobsalaryrange'];
			$education = $_SESSION['resumesearch_heighestfinisheducation'];
			$experience = $_SESSION['resumesearch_experience'];
			$currency = $_SESSION['resumesearch_currency'];

			$result =  $model->getResumeSearch($uid,$title,$name,$nationality,$gender,$iamavailable,$jobcategory,$jobtype,$jobstatus,$currency,$jobsalaryrange,$education
			, $experience,$sortby,$limit,$limitstart);

			$options =  $this->get('Options');
			$sortlinks = $this->getResumeListSorting($sort);
			$sortlinks['sorton'] = $sorton;
			$sortlinks['sortorder'] = $sortorder;
			if ( $result[1] <= $limitstart ) $limitstart = 0;
			$pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
			$this->assignRef('resumes', $result[0]);
			$this->assignRef('searchresumeconfig', $result[2]);
			$this->assignRef('canview', $result[3]);
			$this->assignRef('sortlinks', $sortlinks);
			$this->assignRef('totalRecord', $result[1]);
		}elseif($layout== 'my_resumesearches'){												// my resume searches
			$page_title .=  ' - ' . JText::_('JS_RESUME_SAVE_SEARCHES');
			$result =  $model->getMyResumeSearchesbyUid($uid,$limit,$limitstart);
			$this->assignRef('jobsearches', $result[0]);
			if ( $result[1] <= $limitstart ) $limitstart = 0;
			$pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
		}elseif($layout== 'viewresumesearch'){												// view resume seach
			$page_title .=  ' - ' . JText::_('JS_VIEW_RESUME_SEARCH');
			$id =  JRequest::getVar('rs','');
			$search =  $model->getResumeSearchebyId($id);
			if (isset ($search)){
				$_SESSION['resumesearch_title'] = $search->application_title;
				if($search->nationality != 0) $_SESSION['resumesearch_nationality'] = $search->nationality;
				if($search->gender != 0)$_SESSION['resumesearch_gender'] = $search->gender;
				if($search->iamavailable != 0)$_SESSION['resumesearch_iamavailable'] = $search->iamavailable;
				if($search->category != 0)$_SESSION['resumesearch_jobcategory'] = $search->category;
				if($search->jobtype != 0) $_SESSION['resumesearch_jobtype'] = $search->jobtype;
				if($search->salaryrange != 0) $_SESSION['resumesearch_jobsalaryrange'] = $search->salaryrange;
				if($search->education != 0) $_SESSION['resumesearch_heighestfinisheducation'] = $search->education;
				$_SESSION['resumesearch_experience'] = $search->experience;
					
			}
			$mainframe->redirect( JRoute::_('index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=resume_searchresults&Itemid='.$itemid));
		}elseif($layout== 'job_details'){												// job Details
			//--//
			$jobid =  JRequest::getVar('oi');
			$details =  $model->getJobDetails($jobid);
			$this->assignRef('details', $details);

		}elseif($layout== 'company_info'){												// job Details
			//--//
			$companyid =  JRequest::getVar('md');
			$result =  $model->getCompanyInfoById($companyid);
			$this->assignRef('info', $result[0]);
			$this->assignRef('jobs', $result[1]);
			$this->assignRef('company', $result[2]);
		}elseif($layout== 'jobs'){												// jobs
			//--//
			$result =  $model->getAllForDetails($limit,$limitstart);
			$this->assignRef('jobs', $result[0]);
			$this->assignRef('goldjobs', $result[1]);
			$this->assignRef('featuredcompanies', $result[2]);
			$this->assignRef('goldcompanies', $result[3]);

			//$this->assignRef('limit', $limit);
			//$this->assignRef('limitstart', $limitstart);
		}elseif($layout== 'packages'){												// my resume searches
			$page_title .=  ' - ' . JText::_('JS_PACKAGES');
			$result =  $model->getEmployerPackages($limit,$limitstart);
			$this->assignRef('packages', $result[0]);
			if ( $result[1] <= $limitstart ) $limitstart = 0;
			$pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
		}elseif($layout== 'package_buynow'){
			$page_title .=  ' - ' . JText::_('JS_BUY_NOW');
			$packageid =  JRequest::getVar('gd');

			$result =$model->getEmployerPackageById($packageid,$uid);
			$this->assignRef('package', $result[0]);
			$this->assignRef('payment_multicompanies', $result[1]);
			$this->assignRef('pb', JRequest::getVar('pb',''));
			$this->assignRef('lists', $result[2]);
		}elseif($layout== 'package_details'){
			$page_title .=  ' - ' . JText::_('JS_PACKAGE_DETAILS');
			$packageid =  JRequest::getVar('gd');

			$result =$model->getEmployerPackageById($packageid,$uid);
			$this->assignRef('package', $result[0]);
			$this->assignRef('payment_multicompanies', $result[1]);
			$this->assignRef('lists', $result[2]);

		}elseif($layout== 'purchasehistory'){												// my resume searches
			//$page_title .=  ' - ' . JText::_('JS_PACKAGES');
			$result =  $model->getEmployerPurchaseHistory($uid,$limit,$limitstart);
			$this->assignRef('packages', $result[0]);
			if ( $result[1] <= $limitstart ) $limitstart = 0;
			$pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
		}elseif($layout== 'successfullogin'){												// my resume searches
			if(isset($_SESSION['wrecruit_option'])){ $jsoption = $_SESSION['wrecruit_option']; unset($_SESSION['wrecruit_option']);}
			if(isset($_SESSION['wrecruit_view'])){ $jsview = $_SESSION['wrecruit_view']; unset($_SESSION['wrecruit_view']);}
			if(isset($_SESSION['wrecruit_red_layout'])){ $jslayout = $_SESSION['wrecruit_red_layout']; unset($_SESSION['wrecruit_red_layout']);}
			if(isset($_SESSION['wrecruit_comp_url'])){ $compurl = $_SESSION['wrecruit_comp_url']; unset($_SESSION['wrecruit_comp_url']);}
			if($jslayout == 'successfullogin') $jslayout = 'controlpanel';
			if($jsoption == '') $jsoption =JRequest::getVar('option');
			if($jsoption == '') $jsoption ='com_wrecruit';
			if($jsoption == 'com_wrecruit'){
				if($compurl != ''){
					$mainframe->redirect($compurl);
				}elseif($jsview != ''){
					$mainframe->redirect('index.php?option=com_wrecruit&c=wrecruit&view='.$jsview.'&layout='.$jslayout.'&Itemid='.$itemid);
				}else{ //get role of this user
					if(isset($userrole->rolefor)) {
						if ($userrole->rolefor == 1) { // employer
							$mainframe->redirect('index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=controlpanel&Itemid='.$itemid);
						}elseif ($userrole->rolefor == 2) { // jobseeker
							$mainframe->redirect('index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=controlpanel&Itemid='.$itemid);
						}

					}
				}
			}
			$result =  $model->getEmployerPurchaseHistory($uid,$limit,$limitstart);
			$this->assignRef('packages', $result[0]);
			if ( $result[1] <= $limitstart ) $limitstart = 0;
			$pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
		}elseif($layout== 'empmessages'){ 							// emp messages
			$page_title .=  ' - ' . JText::_('JS_MESSAGES');
			$result =  $model->getMessagesbyJobs($uid,$limit,$limitstart);
			$this->assignRef('messages', $result[0]);
			if ( $result[1] <= $limitstart ) $limitstart = 0;
			$pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
		}elseif($layout== 'job_messages'){ 							// job messages
			$page_title .=  ' - ' . JText::_('JS_MESSAGES');
			$jobid =  JRequest::getVar('bd');
			$result =  $model->getMessagesbyJob($uid,$jobid,$limit,$limitstart);
			$this->assignRef('messages', $result[0]);
			if ( $result[1] <= $limitstart ) $limitstart = 0;
			$pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
		}elseif($layout== 'send_message'){ 							// messages
			$page_title .=  ' - ' . JText::_('JS_MESSAGES');
			$jobid =  JRequest::getVar('bd');
			$resumeid =  JRequest::getVar('rd');
			$result =  $model->getMessagesbyJobResume($uid,$jobid,$resumeid,$limit,$limitstart);
			if ( $result[1] <= $limitstart ) $limitstart = 0;
			$pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
			$this->assignRef('messages', $result[0]);
			$this->assignRef('totalresults', $result[1]);
			$this->assignRef('canadd',$result[2]);
			if(isset($result[3])) $this->assignRef('summary',$result[3]);
			$this->assignRef('bd', $jobid);
			$this->assignRef('rd', $resumeid);
			$this->assignRef('vm', JRequest::getVar('vm'));
		}elseif($layout== 'myfolders'){			// my folders
			$page_title .=  ' - ' . JText::_('JS_MY_FOLDERS');
			$result =  $model->getMyFolders($uid, $limit,$limitstart);
			if ( $result[1] <= $limitstart ) $limitstart = 0;
			$pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
			$this->assignRef('folders', $result[0]);
		}elseif($layout== 'folder_resumes'){      // folder_resumes
			if (isset($_GET['sortby']))
			$sort = $_GET['sortby'];

			$sort =  JRequest::getVar('sortby','');
			if (isset($sort)){
				if ($sort == '')
				{$sort='apply_datedesc';}
			}else
			{$sort='apply_datedesc';}
			$sortby = $this->getEmpListOrdering($sort);
			$folderid =  JRequest::getVar('fd','');
			//$jobid = $mainframe->getUserStateFromRequest( $option.'folderresumes_jobid', 'folderresumes_jobid',	'',	'int' );
			$result =  $model->getFolderResumebyFolderId($uid,$folderid,$sortby,$limit,$limitstart);
			$this->assignRef('resume', $result[0] );
			if ( $result[1] <= $limitstart ) $limitstart = 0;
			$pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
			$this->assignRef('fd', $folderid);
		}

		$document->setTitle( $page_title);
		//if ($mainframe->getCfg('MetaAuthor') == '1') $mainframe->addMetaTag('author', 'WRecruit 1.6');
		$this->assignRef('userrole', $userrole);
		$this->assignRef('config', $config);
		$this->assignRef('theme', $theme);
		$this->assignRef('option', $option);
		$this->assignRef('params', $params);
		$this->assignRef('viewtype', $viewtype);
		$this->assignRef('employerlinks', $employerlinks);
		$this->assignRef('jobseekerlinks', $jobseekerlinks);
		$this->assignRef('uid', $uid);
		$this->assignRef('id', $id);
		$this->assignRef('Itemid', $itemid);
		$this->assignRef('pdflink', $pdflink);
		$this->assignRef('printlink', $printlink);

		parent :: display($tpl);
	}

	function getJobListSorting( $sort ) {
		$sortlinks['title'] = $this->getSortArg("title",$sort);
		$sortlinks['category'] = $this->getSortArg("category",$sort);
		$sortlinks['jobtype'] = $this->getSortArg("jobtype",$sort);
		$sortlinks['jobstatus'] = $this->getSortArg("jobstatus",$sort);
		$sortlinks['company'] = $this->getSortArg("company",$sort);
		$sortlinks['salaryrange'] = $this->getSortArg("salaryrange",$sort);
		$sortlinks['country'] = $this->getSortArg("country",$sort);
		$sortlinks['created'] = $this->getSortArg("created",$sort);
		$sortlinks['apply_date'] = $this->getSortArg("apply_date",$sort);

		return $sortlinks;
	}

	function getResumeListSorting( $sort ) {
		$sortlinks['application_title'] = $this->getSortArg("application_title",$sort);
		$sortlinks['jobtype'] = $this->getSortArg("jobtype",$sort);
		$sortlinks['salaryrange'] = $this->getSortArg("salaryrange",$sort);
		$sortlinks['created'] = $this->getSortArg("created",$sort);

		return $sortlinks;
	}

	function getEmpListSorting( $sort ) {
		$sortlinks['name'] = $this->getSortArg("name",$sort);
		$sortlinks['category'] = $this->getSortArg("category",$sort);
		$sortlinks['jobtype'] = $this->getSortArg("jobtype",$sort);
		$sortlinks['jobsalaryrange'] = $this->getSortArg("jobsalaryrange",$sort);
		$sortlinks['apply_date'] = $this->getSortArg("apply_date",$sort);
		$sortlinks['email'] = $this->getSortArg("email",$sort);
		$sortlinks['gender'] = $this->getSortArg("gender",$sort);
		$sortlinks['age'] = $this->getSortArg("age",$sort);
		$sortlinks['total_experience'] = $this->getSortArg("total_experience",$sort);

		return $sortlinks;
	}

	function getJobListOrdering( $sort ) {
		global $sorton, $sortorder;
		switch ( $sort ) {
			case "titledesc": $ordering = "job.title DESC"; $sorton = "title"; $sortorder="DESC"; break;
			case "titleasc": $ordering = "job.title ASC";  $sorton = "title"; $sortorder="ASC"; break;
			case "categorydesc": $ordering = "cat.cat_title DESC"; $sorton = "category"; $sortorder="DESC"; break;
			case "categoryasc": $ordering = "cat.cat_title ASC";  $sorton = "category"; $sortorder="ASC"; break;
			case "jobtypedesc": $ordering = "job.jobtype DESC";  $sorton = "jobtype"; $sortorder="DESC"; break;
			case "jobtypeasc": $ordering = "job.jobtype ASC";  $sorton = "jobtype"; $sortorder="ASC"; break;
			case "jobstatusdesc": $ordering = "job.jobstatus DESC";  $sorton = "jobstatus"; $sortorder="DESC"; break;
			case "jobstatusasc": $ordering = "job.jobstatus ASC";  $sorton = "jobstatus"; $sortorder="ASC"; break;
			case "companydesc": $ordering = "job.company DESC";  $sorton = "company"; $sortorder="DESC"; break;
			case "companyasc": $ordering = "job.company ASC";  $sorton = "company"; $sortorder="ASC"; break;
			case "salaryrangedesc": $ordering = "salary.rangeend DESC";  $sorton = "salaryrange"; $sortorder="DESC"; break;
			case "salaryrangeasc": $ordering = "salary.rangestart ASC";  $sorton = "salaryrange"; $sortorder="ASC"; break;
			case "countrydesc": $ordering = "country.name DESC";  $sorton = "country"; $sortorder="DESC"; break;
			case "countryasc": $ordering = "country.name ASC";  $sorton = "country"; $sortorder="ASC"; break;
			case "createddesc": $ordering = "job.created DESC";  $sorton = "created"; $sortorder="DESC"; break;
			case "createdasc": $ordering = "job.created ASC";  $sorton = "created"; $sortorder="ASC"; break;
			case "apply_datedesc": $ordering = "apply.apply_date DESC";  $sorton = "apply_date"; $sortorder="DESC"; break;
			case "apply_dateasc": $ordering = "apply.apply_date ASC";  $sorton = "apply_date"; $sortorder="ASC"; break;
			default: $ordering = "job.id DESC";
		}
		return $ordering;
	}

	function getResumeListOrdering( $sort ) {
		global $sorton, $sortorder;
		switch ( $sort ) {
			case "application_titledesc": $ordering = "resume.application_title DESC"; $sorton = "application_title"; $sortorder="DESC"; break;
			case "application_titleasc": $ordering = "resume.application_title ASC";  $sorton = "application_title"; $sortorder="ASC"; break;
			case "jobtypedesc": $ordering = "resume.jobtype DESC";  $sorton = "jobtype"; $sortorder="DESC"; break;
			case "jobtypeasc": $ordering = "resume.jobtype ASC";  $sorton = "jobtype"; $sortorder="ASC"; break;
			case "salaryrangedesc": $ordering = "salary.rangeend DESC";  $sorton = "salaryrange"; $sortorder="DESC"; break;
			case "salaryrangeasc": $ordering = "salary.rangestart ASC";  $sorton = "salaryrange"; $sortorder="ASC"; break;
			case "createddesc": $ordering = "resume.create_date DESC";  $sorton = "created"; $sortorder="DESC"; break;
			case "createdasc": $ordering = "resume.create_date ASC";  $sorton = "created"; $sortorder="ASC"; break;
			default: $ordering = "resume.id DESC";
		}
		return $ordering;
	}

	function getEmpListOrdering( $sort ) {
		global $sorton, $sortorder;
		switch ( $sort ) {
			case "namedesc": $ordering = "app.first_name DESC"; $sorton = "name"; $sortorder="DESC"; break;
			case "nameasc": $ordering = "app.first_name ASC";  $sorton = "name"; $sortorder="ASC"; break;
			case "categorydesc": $ordering = "cat.cat_title DESC"; $sorton = "category"; $sortorder="DESC"; break;
			case "categoryasc": $ordering = "cat.cat_title ASC";  $sorton = "category"; $sortorder="ASC"; break;
			case "genderdesc": $ordering = "app.gender DESC";  $sorton = "gender"; $sortorder="DESC"; break;
			case "genderasc": $ordering = "app.gender ASC";  $sorton = "gender"; $sortorder="ASC"; break;
			case "jobtypedesc": $ordering = "app.jobtype DESC";  $sorton = "jobtype"; $sortorder="DESC"; break;
			case "jobtypeasc": $ordering = "app.jobtype ASC";  $sorton = "jobtype"; $sortorder="ASC"; break;
			case "jobsalaryrangedesc": $ordering = "salary.rangestart DESC";  $sorton = "jobsalaryrange"; $sortorder="DESC"; break;
			case "jobsalaryrangeasc": $ordering = "salary.rangestart ASC";  $sorton = "jobsalaryrange"; $sortorder="ASC"; break;
			case "apply_datedesc": $ordering = "apply.apply_date DESC";  $sorton = "apply_date"; $sortorder="DESC"; break;
			case "apply_dateasc": $ordering = "apply.apply_date ASC";  $sorton = "apply_date"; $sortorder="ASC"; break;
			case "emaildesc": $ordering = "app.email_address DESC";  $sorton = "email"; $sortorder="DESC"; break;
			case "emailasc": $ordering = "app.email_address ASC";  $sorton = "email"; $sortorder="ASC"; break;
			case "total_experiencedesc": $ordering = "app.total_experience DESC";  $sorton = "total_experience"; $sortorder="DESC"; break;
			case "total_experienceasc": $ordering = "app.total_experience ASC";  $sorton = "total_experience"; $sortorder="ASC"; break;
			case "agedesc": $ordering = "job.ageto DESC";  $sorton = "age"; $sortorder="DESC"; break;
			case "ageasc": $ordering = "job.agefrom ASC";  $sorton = "age"; $sortorder="ASC"; break;
			default: $ordering = "job.id DESC";
		}
		return $ordering;
	}

	function getSortArg( $type, $sort ) {
		$mat = array();
		if ( preg_match( "/(\w+)(asc|desc)/i", $sort, $mat ) ) {
			if ( $type == $mat[1] ) {
				return ( $mat[2] == "asc" ) ? "{$type}desc" : "{$type}asc";
			} else {
				return $type . $mat[2];
			}
		}
		return "iddesc";
	}


}
?>
